#!/bin/bash

######################################
# 生成gnome动态桌面的脚本
# 1.将下载的桌面图片存放到一个单独文件夹
# 2.在图片文件夹中运行此脚本，将会生成backgroud-1.xml
# 3.编辑~/.gnome2/backgrouds.xml，照原有内容添加生成的backgroud-1.xml
# author: zhpeng.is@gmail.com
######################################
outfile="background-1.xml"
echo "<background>
		<starttime>
			<year>2009</year>
			<month>08</month>
			<day>04</day>
			<hour>00</hour>
			<minute>00</minute>
			<second>00</second>
		</starttime>
		<!-- This animation will start at midnight. -->" > $outfile

OLDIFS=$IFS
IFS=$'\n'
for pic in $(find -type f -iname "*.JPG" -printf "%f\n"); do
	file[${#file[*]}]=$pic
done
IFS=$OLDIFS

sum=$((${#file[@]}-1))
for (( i = 0 ; i < $sum ; i++ )); do
    echo "<static>
		<duration>1795.0</duration>
		<file>$PWD/${file[$i]}</file>
	</static>
	<transition>
		<duration>5.0</duration>
		<from>$PWD/${file[$i]}</from>
		<to>$PWD/${file[$((i+1))]}</to>
	</transition>" >> $outfile
done;
echo "</background>" >> $outfile

